package cn.kennylee.codehub.springboot.microtrace;

import jakarta.annotation.PostConstruct;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import static cn.kennylee.codehub.springboot.microtrace.TraceProperties.TRACE_ID_CONFIG_PREFIX;

/**
 * <p> 微服务请求跟踪配置 </p>
 * <p>Created on 2025/5/10.</p>
 *
 * @author kennylee
 * @since 0.0.1
 */
@Component
@ConfigurationProperties(prefix = TRACE_ID_CONFIG_PREFIX)
@RefreshScope
@Validated
@Slf4j
@Data
public class TraceProperties {

    public static final String TRACE_ID_CONFIG_PREFIX = "app.trace-id";

    /**
     * 是否启用链路追踪
     */
    private boolean enabled = true;

    /**
     * 是否接收传递的Trace ID
     */
    private boolean acceptTransferTraceId = true;

    /**
     * Trace ID在header中的key名称
     */
    private String traceHeaderName = "X-Trace-Id";

    /**
     * Trace ID在MDC中的key名称
     */
    private String mdcTraceIdName = "traceId";

    /**
     * 是否接受query里面的traceId ## 优先级比header低
     */
    private boolean acceptQueryTraceId = false;

    @PostConstruct
    public void init() {
        log.info("TraceProperties当前配置: {}", this);
    }
}
